package cn.tansanqinger.ThreadPool;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class NewScheduledThreadPoolDemo {
    public static void main(String[] args) {
        //创建定长线程池，可执行周期性的任务
        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(3);
        for (int i = 0; i <3; i++) {
            scheduledThreadPool.scheduleWithFixedDelay(() -> {
                System.out.println(Thread.currentThread().getName());
            }, 0, 3, TimeUnit.SECONDS);
        }
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {}
        System.out.println("10毫秒后...");
        //关闭线程池
        scheduledThreadPool.shutdown();
    }
}
